#pragma once

#include "ConnectionPointReference.h"

#include "Pseudostate.h"
#include "State.h"

namespace uml {

ConnectionPointReference::ConnectionPointReference(const QString& umlType)
    : NamedElement(umlType) {}

void ConnectionPointReference::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    NamedElement::fromJson(json, errorList);
    Vertex::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(entrys_, "entrys", json, errorList);
    JsonSerializable::fromJsonArray(exits_, "exits", json, errorList);
    state_ = JsonSerializable::create<State>(json.value("state"), errorList);

}

void ConnectionPointReference::toJson(QJsonObject& json) {
    NamedElement::toJson(json);
    Vertex::toJson(json);
    JsonSerializable::toJsonArray(entrys_, "entrys", json);
    JsonSerializable::toJsonArray(exits_, "exits", json);
    if (state_) {
        QJsonObject state_json;
        state_->toJson(state_json);
        json.insert("state", state_json);
    }
}

/// <summary>
/// entrys getter
/// The entryPoint Pseudostates corresponding to this connection point.
/// </summary>
vector<shared_ptr<Pseudostate>>& ConnectionPointReference::entrys() {
    return entrys_;
}

/// <summary>
/// exits getter
/// The exitPoints kind Pseudostates corresponding to this connection point.
/// </summary>
vector<shared_ptr<Pseudostate>>& ConnectionPointReference::exits() {
    return exits_;
}

/// <summary>
/// state getter
/// The State in which the ConnectionPointReference is defined.
/// </summary>
shared_ptr<State> ConnectionPointReference::state() const {
    return state_;
}

/// <summary>
/// state setter
/// The State in which the ConnectionPointReference is defined.
/// </summary>
void ConnectionPointReference::setState(shared_ptr<State> value) {
    state_ = value;
}

} // namespace uml
